import { defineStore } from 'pinia';

const useEquipment = defineStore('equipment', {
  // 如何定义state类型
  state: () => ({
    equipment_type: JSON.parse(localStorage.getItem('equipment_type')) || [], // 设备类型
    point_types: JSON.parse(localStorage.getItem('point_types')) || [], //  点位类型
    shui_wei_data: JSON.parse(localStorage.getItem('shui_wei_data')) || [] //  水位站数据
  }),
  getters: {
    equipmentType: (state) => {
      return state.equipment_type;
    },
    pointTypes: (state) => {
      return state.point_types;
    },
    shuiWeiData: (state) => {
      return state.shui_wei_data;
    }
  },
  actions: {
    setEquipmentType(equipment_type) {
      this.equipment_type = equipment_type;
      localStorage.setItem('equipment_type', JSON.stringify(equipment_type));
    },
    setPointType(point_types) {
      this.point_types = point_types;
      localStorage.setItem('point_types', JSON.stringify(point_types));
    },
    setShuiWeiData(shui_wei_data) {
      this.shui_wei_data = shui_wei_data;
      localStorage.setItem('shui_wei_data', JSON.stringify(shui_wei_data));
    }
  }
});
export default useEquipment;
